package com.xxjd.config.converter;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.core.convert.converter.Converter;

import java.time.LocalTime;

/**
 * @author hanxy
 * @ClassName LocalDateTimeConverter
 * @description: TODO
 * @date 2021/7/27 21:21
 */
public class LocalTimeConverter implements Converter<String, LocalTime> {

    @Override
    public LocalTime convert(String dateStr) {
        if (StrUtil.isBlank(dateStr)) {
            return null;
        }
        dateStr = dateStr.trim();
        DateTime date = DateUtil.parse(dateStr);
        return LocalDateTimeUtil.of(date).toLocalTime();
    }
}